﻿using System.Net;
using System.Net.Sockets;
using System.Text;

namespace Untilly.Helper
{
    public class SocketHelper
    {
        public SocketHelper()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Ip"></param>
        /// <param name="Message"></param>
        /// <param name="Port"></param>
        public SocketHelper(string Ip, string Message, int Port = 52000)
        {
            Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            // Connect to the server
            IPAddress ipAddress = IPAddress.Parse(Ip);
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, Port);
            clientSocket.Connect(remoteEP);

            byte[] data = Encoding.ASCII.GetBytes(Message);
            clientSocket.Send(data);

            clientSocket.Shutdown(SocketShutdown.Both);
            clientSocket.Close();
        }
    }
}
